﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ResourceBlender_Express {
    /// <summary>
    /// Allows meta data for GNU PO/gettext file entries to be edited.
    /// </summary>
    public partial class WinEditPO : Window {
        private POMetaData poData;

        /// <summary>
        /// Gets or sets the PO data being edited.
        /// </summary>
        /// <value>The PO data.</value>
        public string POData {
            get { return poData.ToCommentsField(); }
            set {
                poData = POMetaData.Parse(value);
                DataContext = poData;
            }
        }

        /// <summary>
        /// Initializes a new <see cref="WinEditPO"/> to edit the specified raw data.
        /// </summary>
        /// <param name="rawData">The raw data containing the GNU PO information.</param>
        public WinEditPO(string rawData) {
            InitializeComponent();
            this.POData = rawData;
        }

        /// <summary>
        /// Closes the dialog, returning a DialogResult of <c>true</c>.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Save(object sender, RoutedEventArgs e) {
            this.DialogResult = true;
            Close();
        }

        /// <summary>
        /// Shows the help file.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        private void ShowHelp(object sender, ExecutedRoutedEventArgs e) {
            Utils.OpenHelp("PO.Format.html#poedit");
        }

        /// <summary>
        /// Closes the dialog.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void CloseWindow(object sender, RoutedEventArgs e) {
            Close();
        }
    }
}
